#include "Button.h"
#include <iostream>

Button::Button(void):Widget()
{

}


Button::~Button(void)
{
	for(unsigned int j = 0;j < 5;j++)
	{
		for(int i = 0;i < subs[j].size();i++)
		{
			if(subs[(MouseEventType)j][i] != NULL)
			{
				delete subs[(MouseEventType)j][i];
			}
		}

		subs[(MouseEventType)j].clear();
	}
	
}


void Button::onEvent(GuiEvent & evt)
{
	if(evt.type == MOUSE_EVENT)
	{
		
		std::vector<ISubscriber*> * sVec = &subs[(int)evt.mouse.type];

		for(int i = 0;i < sVec->size();i++)
		{
			(*sVec)[i]->callback();
		}

	}
}

void Button::draw(SDL_Renderer * renderer)
{
	SDL_RenderCopy(renderer,texture,NULL,&getArea());
}

void Button::subsribeEvent(MouseEventType evt,ISubscriber * subscriber)
{
	subs[(int)evt].push_back(subscriber);
}